#include "cpuwidget.h"
#include "sysinfo.h"

using namespace QtCharts;

CpuWidget::CpuWidget(QWidget* parent /*= 0*/)
    :SysInfoWidget (parent),
      m_series(new QPieSeries(this))
{
    m_series->setHoleSize(0.35);
    m_series->append("CPU Load", 30.0);
    m_series->append("CPU Free", 70.0);

    QChart* chart = chart_view().chart();
    chart->addSeries(m_series);
    chart->setTitle("CPU average load");
}

void CpuWidget::update_series()
{
    double average_cpu_load = SysInfo::instance().average_cpu_load();
    m_series->clear();
    m_series->append("CPU Load", average_cpu_load);
    m_series->append("CPU Free", 100.0-average_cpu_load);
}
